using UnityEngine.UI;

public class DialogNoLives : GenericDialog
{
	public Button buttonBuy1;

	public Button buttonBuy2;

	public Button buttonBuy3;

	public Text textQuantityBuy1;

	public Text textQuantityBuy2;

	public Text textQuantityBuy3;

	public Text textPriceBuy1;

	public Text textPriceBuy2;

	public Text textPriceBuy3;

	private void OnEnable()
	{
		//if (Globals.appState != 0 && Globals.appState != AppState.unknown)
		//{
		//	Economy.LivesChangedEvent += OnLivesChanged;
		//	UpdateBuy();
		//	UserInterface.GetInstance().ShowInGameDarken();
		//	CustomAnalytics.LogUIEvent("Game", "Zero Lives");
		//	GenericDialog.FireDialogEnabledEvent();
		//}
	}

	private void OnDisable()
	{
		//if (Globals.appState != 0 && Globals.appState != AppState.unknown)
		//{
		//	Economy.LivesChangedEvent -= OnLivesChanged;
		//	UserInterface.GetInstance().HideInGameDarken();
		//}
	}

	private void OnLivesChanged(int deltaLives)
	{
		if (Economy.lives > 0)
		{
			UserInterface.GetInstance().FinishRespawn();
			FadeOut();
		}
	}

	private void UpdateBuy()
	{
		buttonBuy1.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack1);
		buttonBuy2.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack2);
		buttonBuy3.interactable = Economy.CanPurchase(IAPManager.ProductType.LivesPack3);
		textQuantityBuy1.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack1).ToString();
		textQuantityBuy2.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack2).ToString();
		textQuantityBuy3.text = Economy.GetQuantityForProduct(IAPManager.ProductType.LivesPack3).ToString();
		textPriceBuy1.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack1);
		textPriceBuy2.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack2);
		textPriceBuy3.text = Economy.GetFormattedPriceForProduct(IAPManager.ProductType.LivesPack3);
	}

	public void OnBuy1()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Game", "Zero Lives - Buy 1");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.LivesPack1);
	}

	public void OnBuy2()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Game", "Zero Lives - Buy 2");
        UserInterface.GetInstance().dialogPurchaseTips.Reset();
        AdManager.single.ShowVideo(() => { 
			Economy.instance.IAPSuccess(IAPManager.ProductType.LivesPack2);
            UserInterface.GetInstance().dialogPurchaseTips.PurchaseSuccess();
        });
        UserInterface.GetInstance().OnDisplayPurchaseTips();
    }

	public void OnBuy3()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Game", "Zero Lives - Buy 3");
		UserInterface.GetInstance().DoPurchase(IAPManager.ProductType.LivesPack3);
	}

	public void OnReward()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Game", "Zero Lives - Rewards");
		UserInterface.GetInstance().ExitLevel(0f, UserInterface.GetInstance().dialogNotifications);
		FadeOut();
	}

	public void OnImprove()
	{
		Audio.PlaySoundButton();
		CustomAnalytics.LogUIEvent("Game", "Zero Lives - Free Play");
		UserInterface.GetInstance().ExitLevel(0f);
		FadeOut();
	}
}
